package xxl.robotlegs.utils 
{
	import xxl.robotlegs.framework.api.IInjector;
	/**
	 * ...
	 * @author XXL
	 */
	public class GuardUtil 
	{
		
		[Inline]
		public static function GuardsApprove(guards:Array, injector:IInjector):Boolean
		{
			const len:int = guards.length;
			for (var i:int = 0; i < len; i++) 
			{
				var guard:Object = guards[i];
				if (guard is Function)
				{
					if ((guard as Function)())
					{
						continue;
					}
					return false;
				}
				if (guard is Class)
				{
					guard = injector 
						? injector.instantiateUnmapped(guard as Class)
						: new (guard as Class);
				}
				if (guard.approve() == false)
				{
					return false;
				}
			}
			return true;
		}
		
	}

}